<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>
        收付流水
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../../css/main.css" media="all">
    <script type="text/javascript" src="../../../lib/loading/okLoading.js"></script>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="../../../lib/layui/css/layui_2.5.7.css">


</head>
<!--收付流水-->
<style>
    .layui-form-label {
        width: 150px !important;
    }
</style>

<body>
<div class="x-nav">
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon"
                                                                        style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body" id="app">
    <form class="layui-form layui-form-pane" id="add">
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label" id="skrq"> <span class='x-red'>*</span>收款日期</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" id="collectionDate" name="collectionDate"
                               v-model="collectionAndPaymentFlow.collectionDate"
                               lay-verify="required" placeholder="请选择" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>收支途径</label>
                    <div class="layui-input-inline">
                        <select name="revenueAndExpenditureChannels" lay-verify="required">
                            <option value="">---</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label" id="fkdw"> <span class='x-red'></span>付款单位</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="payer" v-model="collectionAndPaymentFlow.payer"
                               placeholder="请输入" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>资金账户</label>
                    <div class="layui-input-inline">
                        <select name="capitalAccount" lay-verify="required">
                            <option value="">---</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>选择类型</label>
                    <div style="width: 74%"  class="layui-input-inline">
                        <select   lay-filter="selectType" name="selectType" lay-verify="required">
                            <option value="">---</option>
                            <option value="销售">销售</option>
                            <option value="工程">工程</option>
                            <option value="维保">维保</option>
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>关联项目</label>
                    <div  style="width: 74%"  class="layui-input-inline">
                        <select name="projectName" lay-filter="projectName" lay-verify="required">
                            <option value="">---</option>
                        </select>
                        <!--<input  autocomplete="off"  type="text" name="projectName" v-model="collectionAndPaymentFlow.projectName"-->
                        <!--placeholder="项目名称" class="layui-input">-->
                    </div>
                </div>
                <!--<div class="layui-inline layui-form-item">-->
                <!--<label class="layui-form-label"> <span class='x-red'></span>凭据编号</label>-->
                <!--<div class="layui-input-inline">-->
                <!--<input  autocomplete="off"  type="text" name="credentialNumber" v-model="collectionAndPaymentFlow.credentialNumber"-->
                <!--placeholder="凭据编号" class="layui-input">-->
                <!--</div>-->
                <!--</div>-->
                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>未付金额</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  style="background: #faebd7" disabled readonly type="number" name="voucherAmount"
                               placeholder="0" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>款项类型</label>
                    <div class="layui-input-inline">
                        <select name="typeOfPayment" lay-verify="required">
                            <option value="">---</option>
                        </select>
                    </div>
                </div>

                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label" id="skje"> <span class='x-red'>*</span>收款金额</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="number" min="0" name="amountCollected" lay-filter="amountCollected"
                               lay-verify="required" placeholder="收款金额" class="layui-input">
                    </div>
                </div>


                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>经手人</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="manager" v-model="collectionAndPaymentFlow.manager"
                               placeholder="经手人" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>摘要备注</label>
                    <div style="width: 70%" class="layui-input-inline">
                         <textarea name="remarks" placeholder="请输入内容" v-model="collectionAndPaymentFlow.remarks"
                                   class="layui-textarea"></textarea>
                    </div>
                </div>

                <div style="text-align: center" class="layui-form-item">
                    <button class="layui-btn" type="button" lay-filter="sub" lay-submit="sub">
                        保存
                    </button>
                </div>
                <!--</form>-->
                <div style="height:20px;"></div>
            </div>


        </div>
        <p style="color: red">注意：保存后，上面的内容才生效。同时请认真核对款项内容是否正确，提交后禁止再次修改！！！！！</p>
    </form>
</div>
<script type="text/javascript" src="../../../js/jquery.min.js"></script>
<script type="text/javascript" src="../../../js/myAjax.js"></script>
<script type="text/javascript" src="../../../js/pub.js"></script>
<script src="../../../lib/layui/layui2.5.7.js" charset="utf-8"></script>
<script src="../../../js/x-layui.js" charset="utf-8"></script>
<script src="../../../js/vue.min.js" charset="utf-8"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js"></script>

<script>
    layui.use(['element', 'layer', 'form', 'laydate'], function () {
        $ = layui.jquery;//jquery
        lement = layui.element();//面包导航
        layer = layui.layer;//弹出层
        laydate = layui.laydate;//日期插件
        form = layui.form;
        okLoading.close($);
    })

</script>
<script>

    var recordId = getQueryVariable("recordId");
    var type = getQueryVariable("type");

    if (type === 'fk') {
        $("#skrq").text('付款日期');
        $("#skje").text('付款金额');
        $("#fkdw").text('收款单位');

    }

    layui.use(['laydate', 'form', 'layer'],
        function () {
            var laydate = layui.laydate;
            var $ = layui.jquery;
            var form = layui.form;
            var layer = layui.layer;

            laydate.render({
                elem: '#collectionDate', //指定元素
                trigger: 'click',
                type: 'date',
                done: function (value, date, endDate) {
                    vm.collectionAndPaymentFlow.collectionDate = value
                }
            });

            //监听审批提交
            form.on('submit(sub)',
                function (data) {
                    let selectType =  $('select[name=selectType]').val();
                    let form = data.field;
                    form.userId = $userId;
                    form.detailId = vm.collectionAndPaymentFlow.detailId;
                    vm.collectionAndPaymentFlow.id == null ? form.operationType = 'add' : form.operationType = 'edit';
                    type === 'sk' ? form.type = '收款' : form.type = '付款';
                    form.operator = $nickName;
                    form.capitalAccountId = form.capitalAccount;
                    form.projectNameId = form.projectName;
                    form.projectName = $("select[name=projectName]").find("option:selected").text();
                    form.capitalAccount = $("select[name=capitalAccount]").find("option:selected").text();
                    form.selectType = selectType;
                    let request = {
                        url: 'collectionAndPaymentFlow/addCollectionAndPaymentFlowItem',
                        data: form,
                        method: "post",
                    };
                    sendRequest(request, (data) => {
                        if (data.code === 0) {
                            layer.alert("操作成功", {
                                    icon: 6
                                },
                                function () {
                                    var index = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(index);
                                    parent.reload();

                                });
                        } else {
                            layer.alert(data.msg, {
                                icon: 5
                            })
                        }
                    });
                    return false;
                });

            form.on('select(projectName)', function (data) {
                let selectType =  $('select[name=selectType]').val();

                if(selectType === '销售' || selectType === '工程'){
                    let request = {
                        url: '/xa/contractInfo/findContractInfo',
                        method: 'GET',
                        data: {
                            userId: $userId,
                            id: data.value
                        }
                    }
                    sendRequest(request, res => {
                        $("input[name=voucherAmount]").val(res.data.contractNoHappenAmount)
                        $("input[name=amountCollected]").val('');
                        // form.render('select');
                    })
                }else{
                    let request = {
                        url: 'maintenanceContract/findMaintenanceContract',
                        method: 'POST',
                        data: {
                            userId: $userId,
                            recordId: data.value
                        }
                    }
                    sendRequest(request, res => {
                        console.log(res);

                        let val = Number(res.data.totalContractAmount) - Number(res.data.paidContractAmount);
                        $("input[name=voucherAmount]").val(val)
                        $("input[name=amountCollected]").val('');
                        // form.render('select');
                    })
                }

            });


            form.on('select(selectType)', function (data) {
                $("select[name=projectName]").empty();
                $("input[name=voucherAmount]").val('');
                if(data.value === '销售' || data.value === '工程'){
                    //合同名称 contractNature 收款1 付款2
                    let request4 = {
                        url: 'xa/contractInfo/findByDelFlag',
                        data: {
                            userId: $userId,
                            delFlag: 0,
                            contractNature: type === 'fk' ? 2 : 1
                        },
                        method: "GET",
                    };
                    sendRequest(request4, (res) => {
                        let x = res.data;
                        console.log(x);
                        $.each(x, function (index, item) {
                            let opt = $("<option value=" + item.id + ">" + item.project.name + "-" + item.customerName + "</option>");
                            $("select[name=projectName]").append(opt);
                        });
                        form.render('select');
                    });
                }else {
                    let request5 = {
                        url: 'maintenanceContract/findMaintenanceContractAll',
                        data: {
                            userId: $userId,
                        },
                        method: "GET",
                    };
                    sendRequest(request5, (res) => {
                        console.log(res);
                        let x = res.data;
                        $.each(x, function (index, item) {
                            let opt = $("<option value=" + item.id + ">" + item.entryName + "-" + item.contractNo + "</option>");
                            $("select[name=projectName]").append(opt);
                        });
                        form.render('select');
                    });

                }
                form.render('select');
            });


        });


    const vm = new Vue({
        el: "#app",
        data: {
            collectionAndPaymentFlow: {
                detailId: null,
                collectionDate: null,
                revenueAndExpenditureChannels: null,
                payer: null,
                capitalAccount: null,
                capitalAccountId: null,

                projectName: null,
                credentialNumber: null,
                voucherAmount: null,
                amountCollected: null,
                typeOfPayment: null,
                manager: null,
                remarks: null,
            }
        },
        created() {

            // let request = {
            //     url: 'billFlow/findBillFlow',
            //     data: {
            //         userId: $userId,
            //         recordId: recordId
            //     },
            //     method: "POST"
            // }
            // sendRequest(request, (res) => {
            //     console.log(res);
            //     this.collectionAndPaymentFlow = res.data;
            // })

        },
        computed: {},
        methods: {},


    });

    setTimeout(() => {
        //修改状态
        let form = layui.form;
        //收支途径
        let request = {
            url: 'dictionary/findDataDictionaryValue',
            data: {
                userId: $userId,
                label: 'REVENUE_AND_EXPENDITURE_CHANNEL'
            },
            method: "POST",
        };
        sendRequest(request, (res) => {
            let x = res.data;
            $.each(x, function (index, item) {
                let opt = $("<option value=" + item + ">" + item + "</option>");
                $("select[name=revenueAndExpenditureChannels]").append(opt);

            });

            // $("select[name=revenueAndExpenditureChannels]").val(vm.collectionAndPaymentFlow.revenueAndExpenditureChannels);

            form.render('select');
        });
        //款项类型
        let request3 = {
            url: 'dictionary/findDataDictionaryValue',
            data: {
                userId: $userId,
                label: 'TYPE_OF_PAYMENT'
            },
            method: "POST",
        };
        sendRequest(request3, (res) => {
            let x = res.data;
            $.each(x, function (index, item) {
                let opt = $("<option value=" + item + ">" + item + "</option>");
                $("select[name=typeOfPayment]").append(opt);
            });

            // $("select[name=typeOfPayment]").val(vm.collectionAndPaymentFlow.typeOfPayment);

            form.render('select');
        });

        //资金账户
        let request2 = {
            url: 'companyAccount/findCompanyAccountSelect',
            data: {
                userId: $userId,
            },
            method: "POST",
        };
        sendRequest(request2, (res) => {
            let x = res.data;
            $.each(x, function (index, item) {
                let opt = $("<option value=" + item.id + ">" + item.accountName + "</option>");
                $("select[name=capitalAccount]").append(opt);

            });
            // $("select[name=capitalAccount]").val(vm.collectionAndPaymentFlow.capitalAccount);

            form.render('select');
        });


        // //合同名称 contractNature 收款1 付款2
        // let request4 = {
        //     url: 'xa/contractInfo/findByDelFlag',
        //     data: {
        //         userId: $userId,
        //         delFlag: 0,
        //         contractNature: type === 'fk' ? 2 : 1
        //     },
        //     method: "GET",
        // };
        // sendRequest(request4, (res) => {
        //     let x = res.data;
        //     console.log(x);
        //     $.each(x, function (index, item) {
        //         let opt = $("<option value=" + item.id + ">" + item.project.name + "-" + item.customerName + "</option>");
        //         $("select[name=projectName]").append(opt);
        //     });
        //
        //     // $("select[name=projectName]").val(vm.collectionAndPaymentFlow.projectName);
        //
        //     form.render('select');
        // });


    }, 300);

    let ac = $("input[name=amountCollected]");
    ac.on("input", function (e) {
        let value = e.delegateTarget.value;
        let maxValue = $("input[name=voucherAmount]").val();
        //获取input输入的值
        if (Number(value) > (Number(maxValue))) {
            ac.val(maxValue);
        } else {
            ac.val(value);
        }
    })

</script>

</body>

</html>
